package dao.hibernateImpl.infocenter;

import java.util.List;


import model.basic.BASICINFOMODEL;
import model.basic.BASICTOINDEXBRIDGE;
import model.basic.CLICK;
import model.basic.FILE;
import model.basic.INFOMATION;
import model.basic.TARGETINTERFACE;
import model.basic.TOINDEX;
import model.basic.UUUADMIN;
import model.commerce.basic.COMMERCE;





import model.photo.basic.PHOTO;
import model.video.basic.VIDEO;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;



import dao.INFOCENTERDAO;



import dao.helper.HibernateConfigurationHelper;
import dao.hibernateImpl.IndexHibernateImpl;


public class INFOCENTERHibernateImpl extends IndexHibernateImpl implements INFOCENTERDAO{



	
	INFOMATION info=new INFOMATION();
	CLICK click=new CLICK();

	TOINDEX toindex=new TOINDEX();
	UUUADMIN uuadmin=new UUUADMIN();
	BASICINFOMODEL bm=((BASICINFOMODEL)info);

	FILE file=new FILE();

	dao.helper.HibernateConfigurationHelper hh=new HibernateConfigurationHelper();
	public List findTop17To6InfoByInter2(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(),this.buildWhereByToTopByINTERNATIONAL(2).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByVideoByInter2(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(), buildWhereByToTopByVIDEOAndINTERNATIONAL(2).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByPhotoByInter2(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(), buildWhereByToTopByPHOTOAndINTERNATIONAL(2).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByCOMMERCEByInter2(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(), buildWhereByToTopByCOMMERCEAndINTERNATIONAL(2).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByInter1(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(),this.buildWhereByToTopByINTERNATIONAL(1).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByVideoByInter1(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(), buildWhereByToTopByVIDEOAndINTERNATIONAL(1).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByPhotoByInter1(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(), buildWhereByToTopByPHOTOAndINTERNATIONAL(1).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	public List findTop17To6InfoByCOMMERCEByInter1(){
		String sql="";
		
		sql=buildBasicSql(this.buildToTopColumnSql().toString(), this.buildToTopTableSql().toString(), buildWhereByToTopByCOMMERCEAndINTERNATIONAL(1).toString(), buildOrderByPubTimeDesc().toString()).toString();
		this.setSql(sql);
		
		return this.findList(0, 17);
		
	}
	
	public StringBuffer buildToTopColumnSql(){
		StringBuffer sb=new StringBuffer();
		sb.append(hh.getTableName(info.getClass()));
		sb.append(this._point);
		sb.append(info.get_ID());
		sb.append(this._comma);
		sb.append(info.get_TITLE());
		sb.append(this._comma);
		sb.append(uuadmin.get_MEMBERNAME());
		return sb;
	}

	public StringBuffer buildOrderByPubTimeDesc(){
		StringBuffer sb=new StringBuffer();
		sb.append(this._orderby);
		sb.append(this._space);
		sb.append(info.get_PUBTIME());
		return sb;
	}

	public StringBuffer buildToTopTableSql(){
		StringBuffer sb=new StringBuffer();
		sb.append(selfTable());

		sb.append(buildToUuAdminRalationsSql());
		return sb;
	}
	public StringBuffer buildWhereByToTopByINTERNATIONAL(int INTERNATIONAL){
		StringBuffer sb=new StringBuffer();
		sb=buildWhereByCondiByINTERNATIONAL(info.get_INTERNATIONAL(),INTERNATIONAL);
//		System.out.println(sb.toString());
		return sb;
	}
	public StringBuffer buildWhereByToTopByVIDEOAndINTERNATIONAL(int INTERNATIONAL){
		StringBuffer sb=new StringBuffer();
		sb=buildWhereByCondi(info.get_CHILDRENTABLE(),hh.getTableName(VIDEO.class));
//		System.out.println(sb.toString());
		return sb;
	}
	public StringBuffer buildWhereByToTopByPHOTOAndINTERNATIONAL(int INTERNATIONAL){
		StringBuffer sb=new StringBuffer();
		sb=buildWhereByCondi(info.get_CHILDRENTABLE(),hh.getTableName(PHOTO.class));
		return sb;
	}
	public StringBuffer buildWhereByToTopByCOMMERCEAndINTERNATIONAL(int INTERNATIONAL){
		StringBuffer sb=new StringBuffer();
		sb=buildWhereByCondi(info.get_CHILDRENTABLE(),hh.getTableName(COMMERCE.class));
		sb.append(this._and);
		sb.append(buildWhereByCondiByINTERNATIONAL(info.get_INTERNATIONAL(),INTERNATIONAL));
		return sb;
	}
	public StringBuffer buildWhereByCondi(String condiname,String tbname){
		
		StringBuffer sb=new StringBuffer();
		sb.append(this.where);
		sb.append(this._space);
		sb.append(condiname);
		sb.append(this._eq);
		sb.append("'");
		sb.append(tbname);
		sb.append("'");
		
		return sb;	
	}
	public StringBuffer buildWhereByCondiByINTERNATIONAL(String condiname,int inter){
		
		StringBuffer sb=new StringBuffer();
		sb.append(this.where);
		sb.append(this._space);
		sb.append(condiname);
		sb.append(this._eq);

		sb.append(inter);
		
		return sb;	
	}
	public StringBuffer selfTable(){
		StringBuffer sb=new StringBuffer();
		String selftb=hh.getTableName(info.getClass());
		sb.append(selftb);
		
		
		return sb;
	}



	public StringBuffer buildToUuAdminRalationsSql(){
		StringBuffer sb=new StringBuffer();
		TARGETINTERFACE ti=new BASICTOINDEXBRIDGE();
		String bmID=bm.get_ID();
		String ralationtb="";
		String selftb=hh.getTableName(info.getClass());
		String targettb=hh.getTableName(uuadmin.getClass());
		sb=buildRalationSql(ti,bmID,ralationtb,selftb,targettb,"",info.get_PUBLISHER());
		
		return sb;
		
	}





	
	
	public static void main(String[] args) {
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		
		INFOCENTERDAO ch=(INFOCENTERDAO)ac.getBean("INFOCENTERDAO");
//		BASICCATEGORY bc=new model.video.category.VIDEOCATEGORY();
		System.out.println(((Object [])(ch.findTop17To6InfoByVideoByInter1().get(0)))[0]);
//		StringBuilder sb=ch.buildToIndexRalationsSql(new StringBuilder());
//		System.out.println(sb.toString());
	}
}
